<?php
if(!defined("IN_PHPSCUP"))exit("hacking");
class Nav
{

    var $_config = array();//导航设置数据 

    var $_file = '';//导航数据文件
   	
    function __construct($filename = '',$lang = '')
    {
        $this->Nav($filename);
    }

    function Nav($filename = '',$lang = '')
    {        
        $this->_file = ROOT_PATH . '/data/nav/' . (!empty($filename)?$filename:$GLOBALS['SCup']->SCup_name) . '.' . (!empty($lang)?$lang:$GLOBALS['Lang']->_lang_tp) . '.nav.php';
    }

    function set_file($filename = '',$lang = '')
    {        
        $this->_file = ROOT_PATH . '/data/nav/' . (!empty($filename)?$filename:$GLOBALS['SCup']->SCup_name) . '.' . (!empty($lang)?$lang:$GLOBALS['Lang']->_lang_tp) . '.nav.php';
    }


    function _get_nav()//得到导航
    {   

		      if(is_file($this->_file))
		      {	    
		           $this->_config = require ($this->_file);
		      }
			  else
			  {
			       $this->_config = array();
			  }


		return $this->_config;   
    }


    //$postdata是提交过来的数据
    function _set_nav($postdata = array(),$name = '')//设置导航
    {   
	    if(empty($postdata))
		{
		     return false;
		}

        $this->_config = $this->_get_nav();
				
		array_push($this->_config,$postdata);
		
		array_var_sort($this->_config,$name);	
				  
	    write_file($this->_file, "<?php if(!defined('IN_PHPSCUP'))exit('hacking'); \nreturn " . var_export($this->_config , true) . ";\n?>");
		
		if(!is_writable($this->_file))
		{
		exit('file directory is not writed power');//文件目录权限不可写
	    }
		   
    
    }



}


?>